/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package system.handlers.admincommands;

import java.util.TreeSet;

import javolution.util.FastMap;

import com.aionemu.gameserver.configs.administration.AdminConfig;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.gameobjects.stats.OwnedStatModifier;
import com.aionemu.gameserver.model.gameobjects.stats.StatEnum;
import com.aionemu.gameserver.utils.PacketSendUtility;
import com.aionemu.gameserver.utils.chathandlers.AdminCommand;
import com.aionemu.gameserver.utils.chathandlers.AdminCommandChatHandler;

/**
 * @author Mr. Poke
 *
 */
public class Stat extends AdminCommand
{

	protected Stat()
	{
		super("stat");
	}

	/* (non-Javadoc)
	 * @see com.aionemu.gameserver.utils.chathandlers.AdminCommand#executeCommand(com.aionemu.gameserver.model.gameobjects.player.Player, java.lang.String[])
	 */
	@Override
	public void executeCommand(Player admin, String[] params)
	{
		if (admin.getAccessLevel() < AdminConfig.COMMAND_STAT)
		{
			PacketSendUtility.sendMessage(admin, "You dont have enough rights to execute this command");
			return;
		}

		if (params == null || params.length != 1)
		{
			PacketSendUtility.sendMessage(admin, "syntax //stat <StatEnum>");
			return;
		}
		StatEnum stat;
		try
		{
			stat = StatEnum.valueOf(params[0].toUpperCase());
		}
		catch (Exception e)
		{
			PacketSendUtility.sendMessage(admin, "Bad stat name!");
			return;
		}
		Player target = (Player) admin.getTarget();
		if (target == null)
			return;
		FastMap<StatEnum, TreeSet<OwnedStatModifier>> stats = target.getGameStats().getStats();

		for (OwnedStatModifier oStat : stats.get(stat))
		{
			String name = "";
			if (oStat.getOwner() != null)
			{
				name = oStat.getOwner().toString();
			}
			PacketSendUtility.sendMessage(admin, "    " + name + "   " + oStat.getStatModifier().toString());
		}
	}

	public static void main(String[] args)
	{
		AdminCommandChatHandler.getInstance().registerAdminCommand(new Stat());
	}
}
